<template>
  <div class="app-container">
    <div class="filter-container clearfix">
      <el-input v-model="listQuery.remark" class="filter-item" style="width: 150px;" placeholder="备注" />
      <el-button class="filter-item" type="primary" plain icon="el-icon-search" @click="handleFilter">搜索</el-button>
    </div>

    <el-table v-loading="listLoading" :data="list" border height="725">
      <el-table-column fixed prop="id" align="center" min-width="80" label="id"></el-table-column>
      <el-table-column prop="content" align="center" min-width="100" label="sql"></el-table-column>
      <el-table-column prop="sid" align="center" label="sid"></el-table-column>
      <el-table-column align="center" label="db">
        <template #default="{ row }">
          <span>{{ row.db }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="remark" align="center" label="备注"></el-table-column>
      <el-table-column prop="date" align="center" label="日期"></el-table-column>
      <el-table-column align="center" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="debugsql(scope)">查询</el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import { objectMerge } from '@/utils'
import { historySql } from '@/api/ops'
import Pagination from '@/components/Pagination'
export default {
  name: 'Config',
  components: { Pagination },
  data() {
    return {
      total: 0,
      listQuery: {
        page: 1,
        limit: 100
      },
      searchBarQuery: {},
      listLoading: false,
      list: []
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.getList()
    },
    debugsql(row) {
      // this.$router.push(url)
      this.$emit('switch-tab', 'DebugSql', row) // 通知父组件切换到 DebugSql
    },
    handleFilter(query) {
      this.searchBarQuery = query
      this.getList()
    },
    async getList() {
      const query = objectMerge(this.searchBarQuery, this.listQuery)
      this.listLoading = true
      const res = await historySql(query)
      this.listLoading = false
      this.list = res.data.items
      this.total = res.data.total
    }
  }
}
</script>

<style scoped>
.el-table {
  font-size: 14px;
}

.el-table td,
.el-table th {
  padding: 10px 0 !important;
}

.el-table th>.cell {
  padding-left: 10px;
  padding-right: 10px;
}

.el-table td {
  text-align: left !important;
}
</style>
